<?php
/*

function db_connect(){
    $use_dbver='5.0';
    $db_char='utf8';
    $db_dbname='log';
    $link=@mysql_connect('','redis','');
    if(!$link){
        echo"Cann't connect to DB!";
        exit();
    }
    //编码
    if($use_dbver>='4.1'){
        $q='';
        if($db_char){
            $q='character_set_connection='.$db_char.',character_set_results='.$db_char.',character_set_client=binary';
        }
        if($use_dbver>='5.0'){
            $q.=(empty($q)?'':',').'sql_mode=\'\'';
        }
        if($q){
            @mysql_query('SET '.$q);
        }
    }
    @mysql_select_db($db_dbname);
    mysql_query("set wait_timeout=2880000") or die(mysql_error());
    mysql_query("set interactive_timeout=24*3600*30") or die(mysql_error());
    return $link;
}

$sql="select
 result.id
,result.FlightNum3
,result.FlightNum2
,result.Registration
,result.DepCode
,ArrCode
,result.Lat
,result.Lng
,result.Speed
,result.Altitude
from
(
select
 a.id
,a.FlightNum3
,a.FlightNum2
,a.Registration
,a.DepCode,ArrCode
,a.Lat
,a.Lng
,a.Speed
,a.Altitude
,@v_rownum := @v_rownum+1
,if(@V_Registration=a.Registration,@v_rank:=@v_rank+1,@v_rank:=1) as 'rank_num'
,@V_Registration:=a.Registration
from
(
select
id,
FlightNum3,
FlightNum2,
Registration,
DepCode,ArrCode,
Lat,
Lng,
Speed,
Altitude
from `fa_airnav_".date('Ymd')."`
where DataSource='Veryzhun_YTY' and `Lat`<>0 and `Lng`<>0 and Registration <>''
order by Registration, id desc
)a,
(
select @v_rank:=0,@v_rownum:=0,@V_Registration:=null
) b
) result
where result.rank_num=1";
$link = db_connect();
$result = mysql_query ($sql, $link);

$result_array = array();
while(($tmp = mysql_fetch_assoc($result)) !== false) {
	$temp = array();
	$temp['flight'] = $tmp['Registration'];
	$temp['x'] = $tmp['Lng'];
	$temp['y'] = $tmp['Lat'];
	$temp['speed'] = $tmp['Speed'];
	$temp['height'] = $tmp['Altitude'];
	$result_array[$tmp['Registration']] = $temp;
}
*/
$node = rand();
$result_array = array(
		2=>array('flight'=>2,'x'=>119.6197,'y'=>32.1633,'speed'=>$node,'height'=>2),
		3=>array('flight'=>3,'x'=>119.5197,'y'=>32.6633,'speed'=>$node,'height'=>3),
		4=>array('flight'=>4,'x'=>119.4197,'y'=>32.59633,'speed'=>$node,'height'=>4),
		5=>array('flight'=>5,'x'=>119.3197,'y'=>32.0633,'speed'=>$node,'height'=>5),
		6=>array('flight'=>6,'x'=>119.3097,'y'=>32.0633,'speed'=>$node,'height'=>5),


);

// 给js准备数据
echo json_encode($result_array);die;

?>
<?php
/*
function db_connect(){
    $use_dbver='5.0';
    $db_char='utf8';
    $db_dbname='log';
    $link=@mysql_connect('','redis','');
    if(!$link){
        echo"Cann't connect to DB!";
        exit();
    }
    //编码
    if($use_dbver>='4.1'){
        $q='';
        if($db_char){
            $q='character_set_connection='.$db_char.',character_set_results='.$db_char.',character_set_client=binary';
        }
        if($use_dbver>='5.0'){
            $q.=(empty($q)?'':',').'sql_mode=\'\'';
        }
        if($q){
            @mysql_query('SET '.$q);
        }
    }
    @mysql_select_db($db_dbname);
    mysql_query("set wait_timeout=2880000") or die(mysql_error());
    mysql_query("set interactive_timeout=24*3600*30") or die(mysql_error());
    return $link;
}

$sql="select
 result.id
,result.FlightNum3
,result.FlightNum2
,result.Registration
,result.DepCode
,ArrCode
,result.Lat
,result.Lng
,result.Speed
,result.Altitude
from
(
select
 a.id
,a.FlightNum3
,a.FlightNum2
,a.Registration
,a.DepCode,ArrCode
,a.Lat
,a.Lng
,a.Speed
,a.Altitude
,@v_rownum := @v_rownum+1
,if(@V_Registration=a.Registration,@v_rank:=@v_rank+1,@v_rank:=1) as 'rank_num'
,@V_Registration:=a.Registration
from
(
select
id,
FlightNum3,
FlightNum2,
Registration,
DepCode,ArrCode,
Lat,
Lng,
Speed,
Altitude
from `fa_airnav_".date('Ymd')."`
where DataSource='Veryzhun_YTY' and `Lat`<>0 and `Lng`<>0 and Registration <>''
order by Registration, id desc
)a,
(
select @v_rank:=0,@v_rownum:=0,@V_Registration:=null
) b
) result
where result.rank_num=1";
$link = db_connect();
$result = mysql_query ($sql, $link);

$result_array = array();
while(($tmp = mysql_fetch_assoc($result)) !== false) {
	$temp = array();
	$temp['flight'] = $tmp['Registration'];
	$temp['x'] = $tmp['Lng'];
	$temp['y'] = $tmp['Lat'];
	$temp['speed'] = $tmp['Speed'];
	$temp['height'] = $tmp['Altitude'];
	array_push($result_array, $temp);
}
*/
$node = rand();
$result_array = array(
		2=>array('flight'=>2,'x'=>119.6197,'y'=>32.1633,'speed'=>$node,'height'=>2),
		3=>array('flight'=>3,'x'=>119.5197,'y'=>32.6633,'speed'=>$node,'height'=>3),
		4=>array('flight'=>4,'x'=>119.4197,'y'=>32.59633,'speed'=>$node,'height'=>4),
		5=>array('flight'=>5,'x'=>119.3197,'y'=>32.0633,'speed'=>$node,'height'=>5),
		6=>array('flight'=>6,'x'=>119.3097,'y'=>32.0633,'speed'=>$node,'height'=>5),


);

// 给js准备数据
echo json_encode($result_array);die;

?>